// pages/product-list/product-list.js
Page({
  data: {
    currentPage: 1,
    totalPages: 23,
    products: [
      {
        id: 1,
        name: "华为MatePad11英寸2023款",
        price: 1200,
        publisher: "小明",
        publishTime: "两小时前",
        image: "/images/ipad.jpg",
        customPage:"shangpinxiangqing"
      },
      {
        id: 2,
        name: "蓝牙耳机",
        price: 50,
        publisher: "小李",
        publishTime: "三天前",
        image: "/images/耳机1.jpg",
        tags: ["有运费险", "手机配件商城", "天猫假一罚无用"]
      },
      {
        id: 3,
        name: "蓝牙耳机",
        price: 50,
        publisher: "小李",
        publishTime: "三天前",
        image: "/images/耳机2.jpg",
        tags: ["Redmi Buds 4 Li", "天猫假一罚无用"]
      },
      {
        id: 4,
        name: "蓝牙耳机",
        price: 50,
        publisher: "小李",
        publishTime: "三天前",
        image: "/images/耳机3.jpg"
      }
    ]
  },

  onLoad: function(options) {
    // 页面加载时执行
  },

  goBack: function() {
    wx.navigateBack();
  },

  goToPrevPage: function() {
    if (this.data.currentPage > 1) {
      this.setData({
        currentPage: this.data.currentPage - 1
      });
      this.loadProducts();
    }
  },

  goToNextPage: function() {
    if (this.data.currentPage < this.data.totalPages) {
      this.setData({
        currentPage: this.data.currentPage + 1
      });
      this.loadProducts();
    }
  },

  loadProducts: function() {
    // 模拟加载商品数据
    wx.showLoading({
      title: '加载中...'
    });
    
    setTimeout(() => {
      wx.hideLoading();
      // 这里应该是实际的API调用
    }, 500);
  },

  switchTab: function(e) {
    const url = e.currentTarget.dataset.url;
    wx.switchTab({
      url: url
    });
  },

  onProductTap: function(e) {
    const productId = e.currentTarget.dataset.id;
    wx.navigateTo({
      url: `/pages/product-detail/product-detail?id=${productId}`
    });
  }
});